<template>
  <div class="app-container">
    <div class="blockquote-box">客服链接配置</div>
    <div>
      <el-form ref="MerchantForm" :rules="WithdrawalRules" :model="MerchantForm" :inline="true" label-width="120px"
        size="small">
        <el-form-item label="客服链接" prop="link_url">
          <el-input style="width: 500px;" v-model="MerchantForm.link_url" placeholder="请填写客服链接"></el-input>
        </el-form-item>
      </el-form>
      <div class="submitbtn">
        <el-button type="primary" size="small" @click="submitMerchantForm()" class="savebtn">保存</el-button>
      </div>
    </div>
  </div>
</template>

<script>
  import {
    customerinfo,
    customersave
  } from "@/api/admin/user";
  export default {
    data() {
      return {
        MerchantForm: {
          id: '',
          link_url: ''
        },
        WithdrawalRules: {
          link_url: [{
            required: true,
            message: '请输入客服链接',
            trigger: 'change'
          }],
        }
      };
    },
    mounted() {
      this.getcustomer()
    },
    methods: {
      getcustomer() {
        customerinfo()
          .then((res) => {
            this.MerchantForm.link_url = res.data.link_url
            this.MerchantForm.id = res.data.id
          })
          .catch(() => {});
      },
      submitMerchantForm() {
        this.$refs.MerchantForm.validate((valid) => {
          if (valid) {
            customersave(this.MerchantForm)
              .then((res) => {
                if (res.code !== 200 || res.status !== 1) {
                  this.$messages.error(res.msg);
                  return;
                }
                this.$messages.success('更新成功');
                this.getcustomer()
              })
              .catch(() => {});
          } else {
            return false;
          }
        })
      }
    }
  };
</script>

<style lang="scss" scoped>
  .submitbtn {
    margin-top: 30px;
    width: 100%;
    text-align: center;

    .savebtn {
      height: 36px;
      width: 120px;
    }
  }
</style>
<style lang="scss">
</style>
